/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SComplaintConverter.java
 * Created：		2016年8月21日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.workorder.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.common.SOpeateInfoConverter_v2;
import com.thor.palmmall.rest.repair.converter.SWorkOrderConverter;
import com.thor.palmmall.rest.workorder.ABusinessOrder;
import com.thor.palmmall.spi.workorder.SBusinessOrder;
import com.thor.palmmall.spi.workorder.SBusinessOrderType;


/**
 * @author kennen
 *
 */
public class SBusinessOrderConverter implements Converter<ABusinessOrder, SBusinessOrder> {

  public static SBusinessOrderConverter getInstance() {
    if (instance == null)
      instance = new SBusinessOrderConverter();
    return instance;
  }

  private static SBusinessOrderConverter instance;

  private SBusinessOrderConverter() {
  }

  @Override
  public SBusinessOrder convert(ABusinessOrder source) {
    if (source == null)
      return null;

    SBusinessOrder target = new SBusinessOrder();
    
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCreateInfo(SOpeateInfoConverter_v2.getInstance().convert(source.getCreateInfo()));
    target.setLastModifyInfo(SOpeateInfoConverter_v2.getInstance().convert(source.getLastModifyInfo()));
    target.setBillNumber(source.getBillNumber());
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setBizState(source.getBizState());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setBpmState(source.getBpmState());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmInstance(source.getBpmInstance());
    target.setAbortMsg(source.getAbortMsg());
    target.setWorkOrder(SWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    if (source.getType() != null) {
      target.setType(SBusinessOrderType.valueOf(source.getType().name()));
    }
    target.setHandler(source.getHandler());
    target.setRemark(source.getRemark());
    return target;
  }
}
